---
title: "Cleaning VDEM data"
---

# Load

```{r}
# load packages
  source("helper-packages.R")

# load Vpart Dataset
  vdem_raw <- 
    readRDS("../raw-data/x-vdem/Country_Year_V-Dem_Core_R_v12/V-Dem-CY-Core-v12.rds")
```

# Clean 

```{r}
# clean
  vdem_clean <- 
    vdem_raw %>% 
    select(
      country_name,
      year,
      v2x_regime) %>% 
    mutate(
      vdem_regime_democracy =
        case_when(
          v2x_regime %in% c(2, 3) ~ 1, # democracy
          v2x_regime %in% c(0, 1) ~ 0, # autocracy
          TRUE ~ NA_real_
          ),
      vdem_country_common = countryname(country_name)) %>% 
    select(vdem_country_common, year, vdem_regime_democracy) %>% 
    na.omit()
```

# Save data

```{r}
  saveRDS(vdem_clean, "../cleaned-data/x-6-vdem.rds")
```
